package org.electric.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;
import org.electric.bean.industryBean;
import org.electric.bean.productBean;
import org.electric.service.CompanyService;
import org.electric.util.WriterUtil;

/**
 * Servlet implementation class industryNews
 */
@WebServlet("/industryNews")
public class industryNews extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public industryNews() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response){
		response.setHeader("Content-Type","text/html;charset=utf-8" );
		CompanyService cs=new CompanyService();
		String pagenub=request.getParameter("Newspage");
		int page=0;
		if(pagenub!=null&&!"".equals(pagenub)){
			int numb=Integer.parseInt(pagenub);
			try {
				//获取新闻总条数
				int count=cs.getindustry();
				if(count%5==0){
					page=count/5;
				}else if(count%5!=0){
					page=count/5+1;
				}
				List<industryBean> list=cs.industryDisplay(numb);
				ObjectMapper om= WriterUtil.writeTopage();
				HashMap<String, Object> map= new HashMap<String, Object>();
				map.put("list", list);
				map.put("countall", page);
				om.writeValue(response.getWriter(),map);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
